package com.base.cn.platform.os.controller.op.feedback;

import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.manage.op.feedback.OpFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户反馈接口
 *
 * @author s.li
 * @create 2018-08-30-15:34
 */
@RestController
@RequestMapping("/api/op")
public class ApiFeedbackController extends ApiBaseController {

    @Autowired
    private OpFeedbackService opFeedbackService;

    /**
     * 保存用户反信息
     * @param userId 用户ID
     * @param feedBackEmail 联系反馈用户的邮箱
     * @param context 反馈内容
     * @param imageUrls 反馈图片
     * @return Map<String,Object>
     */
    @RequestMapping("/saveUpdateFeedBack")
    public Map<String,Object> saveUpdateFeedBack(@RequestParam("userId") BigDecimal userId,
                                                 @RequestParam(value = "feedBackEmail",required = false) String feedBackEmail,
                                                 @RequestParam("context") String context,
                                                 @RequestParam(value = "imageUrls",required = false) String imageUrls) throws UnsupportedEncodingException {
        Map<String,Object> feedback = new HashMap<>();
        feedback.put("userId",userId);
        feedback.put("feedBackEmail",feedBackEmail);
        if(StringUtils.isNotEmpty(context)){
            context = URLDecoder.decode(context, "utf-8");
        }
        feedback.put("context",context);
        feedback.put("imageUrls",imageUrls);
        feedback.put("status",1);
        return opFeedbackService.saveUpdateFeedback(feedback);
    }
}
